/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>推送服务相关设置, 请从阿里云注册账户, 并在其控制台获取相关信息。</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <el-form ref="form" :rules="rules" :model="form" label-width="200px">
      <el-form-item label="上传oss开关">
        <el-switch v-model="form.oss_switch" active-value="1" inactive-value="0"></el-switch>
        <p class="notic">是否对商品图片启用对象存储功能</p>
      </el-form-item>
      <el-form-item label="AccessKeyId" prop="oss_key_id">
        <el-input v-model="form.oss_key_id" size="mini"></el-input>
        <p class="notic">对象存储的key id</p>
      </el-form-item>
      <el-form-item label="AccessKeySecret" prop="oss_key_secret">
        <el-input v-model="form.oss_key_secret" size="mini"></el-input>
        <p class="notic">对象存储的key secret</p>
      </el-form-item>
      <el-form-item label="Endpoint" prop="oss_endpoint">
        <el-input v-model="form.oss_endpoint" size="mini"></el-input>
        <p class="notic">对象存储的Endpoint，比如 oss-cn-shenzhen.aliyuncs.com</p>
      </el-form-item>
      <el-form-item label="Bucket" prop="oss_bucket">
        <el-input v-model="form.oss_bucket" size="mini"></el-input>
        <p class="notic">对象存储的 Bucket</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')" :loading="isLoading">确认提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      isLoading: false,
      rules: {
        oss_key_id: [
          { required: true, message: "请输入AccessKeyId", trigger: "blur" }
        ],
        oss_key_secret: [
          { required: true, message: "请输入AccessKeySecret", trigger: "blur" }
        ],
        oss_endpoint: [
          { required: true, message: "请输入Endpoint", trigger: "blur" }
        ],
        oss_bucket: [
          { required: true, message: "请输入Bucket", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getConfigs();
  },
  methods: {
    getConfigs() {
      var that = this;
      this.request
        .get("/mall/configs", {
          params: {
            inc_type: "oss"
          }
        })
        .then(function(res) {
          that.form = res.oss;
        });
    },
    onSubmit(formName) {
      let check = true;
      this.$refs[formName].validate(valid => {
        if (!valid) {
          check = false;
          return false;
        }
      });
      if (!check) return;
      var that = this;
      this.isLoading = true;
      this.request.put("/mall/configs/oss", that.form).then(function(res) {
        if (res.status == 1) {
          that.$message.success("保存成功");
        } else {
          that.$message.error("保存失败,失败原因:" + res.msg);
        }
        that.isLoading = false;
      });
    }
  }
};
</script>
<style scoped>
>>> .el-input__inner {
  width: 300px;
}
</style>
